If the output file exists, it will not be overwritten unless the -f flag is given. If -f is not specified and compress is run in the foreground, the user is prompted as to whether the file should be overwritten.
If the -f flag is given, all files specified are replaced with .Z files - even if the file didn't get smaller.
When file names are given, the ownership (if run by root), modes, accessed and modified times are maintained between the file and its .Z version. In this respect, compress can be used for archival purposes, yet can still be used with make(1) after uncompression.
The -c option causes the results of the compress/uncompress operation to be written to stdout; no files are changed. The zcat program is the same as specifying -c to uncompress (all files are unpacked and written to stdout).
Compress uses the modified Lempel-Ziv algorithm described in "A Technique for High Performance Data Compression", Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19. Common substrings in the file are first replaced by 9-bit codes 257 and up. When code 512 is reached, the algorithm switches to 10-bit codes and continues to use more bits until the bits limit as specified by the -b flag is reached (default 16). Bits must be between 9 and 16. The default can be changed in the source to allow compress to be run on a smaller machine.
After the bits limit is reached, compress periodically checks the compression ratio. If it is increasing, compress continues to use the codes that were previously found in the file. However, if the compression ratio decreases, compress discards the table of substrings and rebuilds it from scratch. This allows the algorithm to adapt to the next "block" of the file. The -C (compatibility) flag prevents subdivision of the file into blocks; this produces an output file that old versions of compress can read.
A two byte magic number is prepended to the file to ensure that neither uncompression of random text nor recompression of compressed text are attempted. In addition, the bits specified during compress is written to the file so that the -b flag can be omitted for uncompress.
The amount of compression obtained depends on the size of the input file, the amount of bits per code, and the distribution of character substrings. Typically, text files, such as C programs, are reduced by 50-60%. Compression is generally much better than that achieved by Huffman coding (as used in pack), or adaptive Huffman coding (compact), and takes less time to compute.
If the -v (verbose) flag is given, then after each file is compressed, a message is printed giving the percentage of the input file that has been saved by compression.
If the -V (version) flag is given, the program's version number is printed.
The exit status is normally 0; if the last file gets bigger after compression, the exit status is 2; if an error occurs, the exit status is 1.